home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / cwdkit.com / CWDKIT5.DOC < prev    next >
Encoding:
Text File  |  1988-12-08  |  20.9 KB  |  476 lines

  1.  
  2.                Centiwrite 1.00 Developer's Kit User's Manual
  3.                ========== ==== =========== === ====== ======
  4.  
  5.                     Copyright 1988 Andrew M. Saucci, Jr.
  6.  
  7.                             What's to Follow
  8.  
  9.  1. Introduction
  10.  2. About the Author
  11.  3. The Interface of the Unit
  12.  4. What You'll Need to Compile
  13.  5. The Basic Principles
  14.  6. A Sample Calling Program
  15.  7. Analysis of the Sample Program
  16.  8. The Initial Values
  17.  9. Initializing the Array
  18. 10. For Extra Punch in Your Program
  19. 11. Down to Brass Tacks
  20. 12. Boilerplate
  21. 13. To All Those Who Helped
  22. 14. Coming Attractions
  23. 15. It's Alive!
  24.  
  25.  =============================================================================
  26.  
  27.                              Introduction
  28.  
  29.           Congratulations on having acquired this useful developer's tool. Now
  30. you can have an "instant editor" in your own programs whenever you need to
  31. include the capability to create short memos, notes, or letters. This file
  32. will attempt to show you how to incorporate the Centiwrite 1.00 editor into
  33. your Turbo Pascal programs. If you are unfamiliar with this editor, you should
  34. definitely obtain a copy of the stand-alone version of Centiwrite and read its
  35. User's Manual. This explains in detail the operation of the editor.
  36.  
  37.  =============================================================================
  38.  
  39.                             About the Author
  40.  
  41.           Andrew M. Saucci, Jr. was graduated with distinction from the
  42. New York Institute of Technology with a master's degree in computer science.
  43. He received a bachelor's degree in computer science from Hofstra University.
  44. The Centiwrite Developer's Kit is his first program to be distributed for
  45. programmers by commercial on-line services. Since purchasing his first personal
  46. computer, a Dell System 200, Mr. Saucci has read extensively about the
  47. IBM-compatible world of computers. Included in his personal library are
  48. The New Peter Norton Programmer's Guide to the IBM PC and PS/2, PC Magazine's
  49. DOS Power Tools, Advanced Turbo Pascal, and subscriptions to almost all major
  50. PC publications, plus some "not-so-major" newsletters and the like.
  51.  
  52.           Mr. Saucci can be reached at any of the following electronic mail
  53. addresses:
  54.  
  55. CompuServe  72117,241
  56. The Source  BFE501
  57. BIX         ASAUCCI
  58. Genie       ASAUCCI3
  59. Delphi      ASAUCCI
  60.  
  61.           Comments about any of his products are most welcome.
  62.  
  63.  =============================================================================
  64.  
  65.                         The Interface of the Unit
  66.  
  67. unit centwri5;
  68. interface
  69.     uses dos, crt;
  70.     type scarray= array [1..60] of string[85];
  71.          commstruc= record
  72.                     screline: scarray;
  73.                     lastring, initWhereX, initWhereY: byte;
  74.                     CurAttr, StdAttr, MessAttr: byte;
  75.                     passkey: char;
  76.                     insmode: boolean;
  77.                     end;
  78.     function nextword (sentence: string): integer;
  79.     function lastword (sentence: string): integer;
  80.     function datestring: string;
  81.     function timestring: string;
  82.     procedure AnalyzeKey (var inkey: char; var excode: boolean;
  83.                             var scancode: byte);
  84.     procedure GetKey (var inkey: char);
  85.     procedure DelWord (var sentence: string; position: integer);
  86.     procedure Centiwrite (var infoexch: commstruc);
  87.  
  88. implementation
  89. { Implementation would follow here. }
  90.  
  91.  
  92. Each of the variables used in the "commstruc" (for "communications structure"
  93. record is described below.
  94.  
  95. screline: The strings which represent each line of the text to a maximum of
  96.           60. This accomodates 25-, 43-, and 50-line screens.
  97.  
  98. lastring: The number of currently "valid" strings in screline. Because a line
  99.           consisting solely of a carriage return (ASCII 13-10) is represented
  100.           by a null string, "lastring" indicates how many lines of screline
  101.           are currently being used. Note that in an empty file, lastring is 1.
  102.  
  103. initWhereX: The initial x-coordinate of the cursor on entry to the editor.
  104.  
  105. initWhereY: The initial y-coordinate of the cursor on entry to the editor.
  106.  
  107. CurAttr: The color attribute of the cursor. You can use any valid attribute.
  108.          If the foreground and background are the same, the Centiwrite editor
  109.          assumes that the blinking hardware cursor is being used, and the
  110.          cursor emulation is disabled. The cursor will appear as a blinking
  111.          CHARACTER if a background color greater than 7 is used.
  112.  
  113. StdAttr: The normal color attribute of the editor.
  114.  
  115. MessAttr: The color attribute for messages which appear on the status line.
  116.  
  117. passkey: The character passed back to the main program when Centiwrite does
  118.          not define a function for it.
  119.  
  120. insmode: If true, then the editor is in Insert mode. Otherwise, Overstrike
  121.          mode is used.
  122.  
  123.  
  124. The functions and procedures which are included are summarized next.
  125.  
  126. nextword: Returns the position of the next word in a string. In the string
  127.           "for he's a jolly good fellow", nextword returns 4. If no "next
  128.           word" is found, the return value is the length of the string plus 1.
  129.  
  130. lastword: Returns the position of the last word in a string. In the string
  131.           "which nobody can deny", lastword returns 18. If the string is a
  132.           single word, the return value is 1.
  133.  
  134. datestring: Returns the current system date in the form "Monday, May 26, 1988".
  135.  
  136. timestring: Returns the current system time in the form "10:45:44 PM".
  137.  
  138. AnalyzeKey: Substitute keyboard reading procedure (for ReadKey). A single
  139.             call returns all pertinent keyboard information-- no need to
  140.             make multiple calls to check for extended key codes.
  141.  
  142. GetKey: Another substitute for ReadKey, but returns extended key codes as
  143.         ASCII zero with a single call.
  144.  
  145. DelWord: Deletes the word starting at a given location in a string.
  146.  
  147. Centiwrite: The editor itself.
  148.  
  149.  =============================================================================
  150.  
  151.                        What You'll Need to Compile
  152.  
  153.           In order to compile a program using Centiwrite, you need to copy
  154. CENTWRI5.TPU into the directory where Turbo Pascal normally looks for your
  155. .TPU files. In version 5.0, this is one of the EXE & TPU directories specified
  156. under the Options/Directories menu selection. You will also need to add the
  157. line "uses centwri5;" to the the source file of the procedure that calls the
  158. editor. Check your Turbo Pascal manual for additional information on including
  159. units in your programs. Oh, yes, you'll also need Turbo Pascal version 5.0.
  160. For those concerned about needing to recompile for future versions of the
  161. compiler, the current plan is to update the unit whenever a new version of
  162. Turbo Pascal is released. Upgrades will be available for a modest charge.
  163.  
  164.  =============================================================================
  165.  
  166.                            The Basic Principles
  167.  
  168.           The Centiwrite editor is based upon an "array of strings"
  169. implementation. While not suitable for a large text editor or word processor,
  170. this approach is quite adequate for a simple program such as this. It allows
  171. a "quick and dirty" style, and is easily understandable. Each element in the
  172. array of strings represents a line of text on the screen. An "implied"
  173. carriage return ends each line. A count of the current number of lines is
  174. maintained at all times. A duplicate array is maintained in memory in order
  175. to facilitate the "Undo" feature (invoked by F3).
  176.  
  177.           Some may wonder why the video memory is not used to store the
  178. text, considering that the text is stored there anyway. Use of character
  179. strings allows the use of Turbo Pascal's string-handling procedures. Using
  180. video memory would mean writing substantially more code in order to duplicate
  181. the functions already available in the runtime library. This code would not
  182. only make the program larger, but would also need to be debugged. The Turbo
  183. Pascal string-handling routines (while not perfect) are already thoroughly
  184. debugged.
  185.  
  186.  =============================================================================
  187.  
  188.                         A Sample Calling Procedure
  189.  
  190.           The following program is an example of how to call the editor.
  191.  
  192. program CallEditor (input, output);
  193. uses dos, crt, centwri5;
  194. var origreg, reg: registers;
  195. cwinfo: commstruc;
  196. i: byte;
  197.  
  198. procedure SaveFile;
  199. begin
  200. writeln ('Code for saving a file would be here.');
  201. end;
  202.  
  203. procedure HelpProcedure;
  204. begin
  205. writeln ('Help! Help!');
  206. end;
  207.  
  208. begin
  209. origreg.ah:= $03;
  210. origreg.bh:= $00;
  211. intr ($10, origreg);  { Save old cursor }
  212. reg.ah:= $01;
  213. reg.ch:= $20;
  214. reg.cl:= $00;
  215. intr ($10, reg);  { Disable hardware cursor }
  216. with cwinfo do    { Allows unqualified variable references. }
  217. begin
  218. insmode:= true;     { Initialize structure variables. }
  219. initWhereX:= 1;
  220. initWhereY:= 1;
  221. CurAttr:= $5F;  { White on Cyan }
  222. StdAttr:= $17;  { LightGray on Blue }
  223. MessAttr:= $20; { Black on Green }
  224. for i:= 1 to 25 do
  225.     screline[i]:= '';  { empty file }
  226. lastring:= 1;
  227. repeat
  228.    window (1, 1, 80, 25);
  229.    TextAttr:= $07;
  230.    ClrScr;
  231.    writeln ('Joe''s Program: Centiwrite Editor-- Alt-X to Exit');
  232.    window (1, 2, 80, 25);
  233.    Centiwrite (cwinfo);      { <------------- PLUG-IN EDITOR }
  234.    window (1, 1, 80, 25);
  235.    TextAttr:= $07;
  236.    if (passkey= #45) or (passkey= #60)  { If Alt-X or F2, save the file. }
  237.       then SaveFile;
  238.    if passkey=#59  { F1 displays a list of keys and their functions. }
  239.       then HelpProcedure;
  240. until ((passkey=#32) or (passkey=#45));  { Alt-D or Alt-X (exit condition) }
  241. end;  { with statement }
  242. ClrScr;
  243. origreg.ah:= $01;
  244. intr ($10, origreg); { restore cursor }
  245. end.  { program }
  246.  
  247.  =============================================================================
  248.  
  249.                        Analysis of the Sample Program
  250.  
  251.           Take a close look at the sample program. Although it has been
  252. simplified in order to highlight the main points, its basic structure is
  253. the same as that of the stand-alone version of Centiwrite 1.00. It gives
  254. initial values to the members of the structure, and then runs the editor
  255. in a repeat..until loop.
  256.  
  257.           Why a loop? This is the means you can use to add your own "frills"
  258. to the editor. Any time the Centiwrite editor sees a key that it does not
  259. recognize, such as F6, Alt-Z, or Ctrl-F5, the editor terminates and control
  260. returns to the calling procedure. Placing the editor in a loop gives you a
  261. chance to execute whatever procedures or functions you like before RETURNING
  262. control, or exiting if you like. For example, Alt-X is the "recommended" exit
  263. key. The editor takes no special action on seeing Alt-X; it merely exits just
  264. the same as it would for any other unrecognized key. The "until" condition
  265. "passkey=#45" is what causes the sample program to terminate. To use F10 as
  266. an exit key, just change the condition to "passkey=#68". Likewise, what
  267. displays help is "passkey=#59"; to use Shift-F1, change to "passkey=#84".
  268.  
  269.          Note that the editor recognizes all keys that return an ASCII value
  270. plus the following extended keys:
  271.  
  272. arrow keys        Shift-Tab          Ctrl-Left arrow       Alt- B E T Y H V
  273. Insert            Home/End           Ctrl-Right arrow      F3  F5  F7  F8
  274. Delete            Ctrl-Home/End      Ctrl-F8
  275.  
  276.          The calling procedure is passed any other keys and may deal with them
  277. however it sees fit. The value passed back to the calling procedure is the
  278. extended value of the last key pressed. An "extended" flag is not necessary
  279. because only extended key codes can be returned. If you need to intercept any
  280. values which are normally recognized by the editor, you must either write an
  281. interrupt $09 or $16 handler that "grabs" the values you want or obtain a
  282. customized version of CENTWRI5.TPU that passes the keys you need. (This is
  283. available for an additional charge.)
  284.  
  285.           Notice the "window" statement just before the call to Centiwrite.
  286. This is absolutely necessary in order for the editor to establish its window
  287. boundaries and insure the integrity of its screen. The editor can operate
  288. in a window no narrower than 40 columns. It has not been tested in windows
  289. shorter than 24 rows; however, it should work for any number of rows greater
  290. than three, which is the minimum. (For a single row "window" you should use
  291. "liminput", the complete source code to which is found in the Deciwrite
  292. Developer's Kit.) If you specify a window size of fewer than 40 columns,
  293. greater than the screen width, or greater than the screen height, the result is
  294. unknown.
  295.  
  296.           The Centiwrite editor redraws its window each time it is called, and
  297. it leaves the screen in place when it exits. Therefore, you can put a window
  298. over it without any trouble.
  299.  
  300.  ============================================================================
  301.  
  302.                           The Initial Values
  303.  
  304.           The most important value in "commstruc" is "lastring". If you use
  305. an invalid value for lastring, the editor will become confused and behave
  306. erratically. Lastring should be 1 for an empty file. Otherwise, it reflects
  307. the number of currently valid strings in the array "screline".
  308.  
  309. Example.
  310.  
  311. If screline is this (line numbers added):
  312.  
  313. [1] Now is the time for all good people.
  314. [2] We must mobilize now.
  315. [3]
  316. [4] May we have your support?
  317.  
  318. then lastring is 4. If two carriage returns are added after line 4, as in
  319.  
  320. [4] May we have your support?
  321. [5]
  322. [6]
  323.  
  324. then lastring is 6. Lastring should only be changed when the number of lines
  325. in the text is changed.
  326.  
  327.           Here's an important note about carriage returns. The Centiwrite
  328. editor does NOT add the ASCII 13-10 combination explicitly to the text. Every
  329. string ends in an IMPLIED 13-10. If you write a file to disk, you must add the
  330. 13-10 yourself. This is easily done using a "writeln(screline[i])"-type
  331. statement. You need not delete a 13-10 on input, however, as the editor
  332. automatically removes these (as well as ASCII 7 and 8) from the text. You
  333. should, however, take care to format the input strings so that they do not
  334. contain embedded carriage returns that really belong at the end of a line.
  335.  
  336.           InitWhereX and initWhereY are used to position the cursor when
  337. the editor is called. For the first invocation, each of these should usually be
  338. set to 1, although any valid values are acceptable. Never position the cursor
  339. below the row "lastring", or erratic operation will result. When the editor
  340. passes control back to the calling procedure, the current cursor position is
  341. saved in initWhereX and initWhereY. It can then be reused if necessary when
  342. the editor is called again. Pressing F6 demonstrates this simply. The cursor
  343. position is saved; the editor returns control to the main program; the main
  344. program ignores the key (because no function has been defined for it there,
  345. either); and the editor regains control, positioning the cursor at the saved
  346. location.
  347.  
  348.           Insmode, as explained earlier, is simply a flag. It's your choice--
  349. set it however you like depending upon whether you want to start the editor in
  350. Insert mode or Overstrike mode.
  351.  
  352.           Passkey need not be initialized. It is strictly a return value.
  353.  
  354.  ============================================================================
  355.  
  356.                            Initializing the Array
  357.  
  358.           You must initialize "screline" before using it. This can be done
  359. any way you like-- with assignment statements, reads, etc. You should assign
  360. an initial value to "maxline" elements in screline, where "maxline" is equal
  361. to the maximum number of lines on the screen plus 1. Be sure to keep "lastring"
  362. synchronized with the actual number of elements of screline in use.
  363.  
  364.  =============================================================================
  365.  
  366.                        For Extra Punch in Your Program
  367.  
  368.           If you want to use a "plug-in editor" in your program, but feel
  369. Centiwrite just isn't powerful enough, don't walk away feeling dejected.
  370. Here's good news! Also available is an editor similar to Centiwrite but ten
  371. times as powerful. It's Deciwrite! The Deciwrite Developer's Kit includes all
  372. the features of Centiwrite PLUS:
  373.  
  374. 1. Automatic word wrap and paragraph reformatting.
  375. 2. Full support for binary files.
  376. 3. Time and date can be inserted into the text with one keystroke.
  377. 4. Full source code-- including liminput, a replacement for readln; dectohex
  378.    and hextodec, hexadecimal conversion routines; and FileCheck, which checks
  379.    for the existence of a file and determines if it is read-only; and more!
  380.  
  381.           What's more, if you're not sure, you can "lock in" the price of
  382. the Deciwrite Developer's Kit by buying the Centiwrite Developer's Kit NOW.
  383. You'll have one year to upgrade at the current price, PLUS you get a credit
  384. for what you paid for the Centiwrite Developer's Kit. What's to lose?
  385. Send electronic mail to the addresses listed earlier to learn how to take
  386. advantage of this great offer.
  387.  
  388.  =============================================================================
  389.  
  390.                            Down to Brass Tacks
  391.  
  392.       As of December 1, 1988, this is the Centiwrite/Deciwrite price list.
  393.  
  394.                                     Individual License        Site License
  395.       Centiwrite 1.00                    $12.50                  $200.00
  396.       Deciwrite  1.00                    $25.00                  $400.00
  397.       Centiwrite 1.00 Developer's Kit
  398.                  For Turbo Pascal 4.0    $22.50                  $350.00
  399.                  For Turbo Pascal 5.0    $27.50                  $450.00
  400.                  Upgrade to 5.0          $ 7.50                  $120.00
  401.       Deciwrite 1.00 Developer's Kit     $60.00                  $900.00
  402.       Disk replacement fee               $ 2.50                    none
  403.  
  404.       New York State residents must add their local sales tax.
  405.  
  406.       Residents of other states will in most cases be required to remit the
  407.       appropriate tax directly to their state tax department.
  408.  
  409.       An individual license permits the user to operate the program on
  410.       a single computer at a time, while a site license permits unlimited use
  411.       within the confines of a contiguous area of the owner's property.
  412.  
  413.       These prices are guaranteed not to increase through April 1, 1989.
  414.  
  415.       Custom implementations of these programs are also available on
  416.       request for modest additional fees. Send electronic mail to one
  417.       of the addresses listed earlier.
  418.  
  419.       At this time, credit cards cannot be accepted.
  420.  
  421.       Make checks payable to
  422.  
  423.       Andrew M. Saucci, Jr.
  424.       727 Barkley Ave
  425.       East Meadow, NY 11554-4502.
  426.  
  427.       Please specify the disk size you require.
  428.  
  429.       You may wish to check one of the electronic mail addresses to verify
  430.       that the above address is current. Please use this "physical" address
  431.       ONLY for orders. All other correspondence, including technical support
  432.       questions, should be directed to one of the electronic mail addresses.
  433.  
  434.  ============================================================================
  435.  
  436.                                Boilerplate
  437.  
  438.           Liability in the event of defects in Centiwrite 1.00 and/or the
  439. Centiwrite 1.00 Developer's Kit is expressly limited to replacement of the disk
  440. on which Centiwrite and/or the Developer's Kit was originally provided. No
  441. other liability of any sort is either implied or assumed. In particular, the
  442. user is responsible for all consequential damages, such as loss of income,
  443. loss of data, pain and suffering, etc.
  444.  
  445.  ============================================================================
  446.  
  447.                         To All Those Who Helped
  448.  
  449.           Thanks to all those who gave their assistance toward the completion
  450. of this program, especially Michael Day, Neil Rubenking, Scott Bussinger, and
  451. all the other helpful people who frequent Borland's Programming Forum A
  452. (BPROGA) on CompuServe. It's truly amazing!
  453.  
  454.  ============================================================================
  455.  
  456.                            Coming Attractions
  457.  
  458.           A plan to produce a full-size text editor based on Centiwrite and
  459. Deciwrite is in the works. Please use Centiwrite to write a short note
  460. describing a few of the features you would like to see in a text editor,
  461. particularly anything that is not found in other programs, and send it to one
  462. of the electronic mail addresses. The result could be a really good program.
  463. You might also indicate what incentives are most likely to cause you to
  464. purchase registered copies of programs distributed on a "try-before-you-buy"
  465. basis. Your suggestions will be most appreciated.
  466.  
  467.  ============================================================================
  468.  
  469.                                It's Alive!
  470.  
  471.           This program is not carved in stone. Many of you no doubt have
  472. extensive experience in this field, and your comments and suggestions are
  473. valuable and welcome. Send them to the electronic mail addresses listed.
  474.  
  475.  ============================= END OF FILE ===================================
  476.